package com.study.design.singleton;

/**
 * 双重校验锁
 *
 * @Author 网易云课堂微专业-java高级开发工程师【allen老师】
 * @Version 1.0
 */
public class Singleton4 {

    // 1
    private volatile static Singleton4 uniqueInstance;

    private Singleton4() {
    }

    public static Singleton4 getUniqueInstance() {
        // 2
        if (uniqueInstance == null) {
            // 3
            synchronized (Singleton4.class) {
                // 4
                if (uniqueInstance == null) {
                    uniqueInstance = new Singleton4();
                }
            }
        }
        return uniqueInstance;
    }
}
